﻿<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="Automator.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Automator"
    Height="700"
    Width="950"
    Loaded="Window_Loaded"
    Closing="Window_Closing" xmlns:ad="clr-namespace:AvalonDock;assembly=AvalonDock" xmlns:automator="clr-namespace:Automator" xmlns:core="clr-namespace:Automator.Tasks.Core;assembly=Automator.Tasks.Core" xmlns:extToolkit="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit.Extended"
    xmlns:classes="clr-namespace:Automator.Classes" xmlns:runtime="clr-namespace:Automator.Runtime;assembly=Automator.Runtime">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary
                    Source="MainWindow.Styles.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="{x:Type TreeViewItem}" x:Key="workflowTreeItemStyle">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="IsExpanded" Value="True" />
                <EventSetter Event="PreviewMouseLeftButtonDown" Handler="treeWorkflow_MouseDown" />
                <EventSetter Event="PreviewMouseMove" Handler="treeWorkflow_MouseMove" />
                <EventSetter Event="DragOver" Handler="treeWorkflow_DragOver" />
                <EventSetter Event="PreviewDrop" Handler="treeWorkflow_Drop" />
                <EventSetter Event="PreviewMouseRightButtonDown" Handler="treeWorkflow_RightClick" />
            </Style>
            
            <Style TargetType="{x:Type TreeViewItem}" x:Key="solutionTreeItemStyle">
                <Setter Property="Background" Value="Transparent" />
                <Setter Property="IsExpanded" Value="True" />
                <EventSetter Event="PreviewMouseRightButtonDown" Handler="treeWorkflow_RightClick" />
            </Style>            
            
            <ContextMenu
                x:Key="mnuBorder"
                Opened="ContextMenu_Opened"
                Closed="ContextMenu_Closed">
                <MenuItem
                    Header="Edit"
                    Margin="1">
                    <MenuItem.Template>
                        <ControlTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition
                                        Width="*" />
                                    <ColumnDefinition
                                        Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock
                                    Text="Edit"
                                    Grid.Column="0"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Stretch"
                                    Margin="32,0,16,0"
                                    IsHitTestVisible="False"
                                    MinWidth="30" />
                                <ToolBarTray
                                    IsLocked="True"
                                    Grid.Column="1"
                                    Background="Transparent"
                                    Focusable="False">
                                    <ToolBar
                                        Loaded="ToolBar_Loaded">
                                        <Button
                                            Command="automator:AutomatorCommands.AddDependency"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/adddependent.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                        <Button
                                            Command="automator:AutomatorCommands.EditTask"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/edit.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                        <Button
                                            Command="automator:AutomatorCommands.DeleteTask"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/delete.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                    </ToolBar>
                                </ToolBarTray>
                            </Grid>
                        </ControlTemplate>
                    </MenuItem.Template>
                </MenuItem>
                <Separator />
                <MenuItem
                    Header="Clipboard"
                    Margin="1">
                    <MenuItem.Template>
                        <ControlTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition
                                        Width="*" />
                                    <ColumnDefinition
                                        Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock
                                    Text="Clipboard"
                                    Grid.Column="0"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Stretch"
                                    Margin="32,0,16,0"
                                    IsHitTestVisible="False"
                                    MinWidth="30" />
                                <ToolBarTray
                                    IsLocked="True"
                                    Grid.Column="1"
                                    Background="Transparent"
                                    Focusable="False">
                                    <ToolBar
                                        Loaded="ToolBar_Loaded">
                                        <Button
                                            Command="automator:AutomatorCommands.Cut"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/cut.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                        <Button
                                            Command="automator:AutomatorCommands.Copy"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/copy.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                    </ToolBar>
                                </ToolBarTray>
                            </Grid>
                        </ControlTemplate>
                    </MenuItem.Template>
                </MenuItem>
                <Separator />
                <MenuItem
                    Header="Run Task"
                    Margin="1">
                    <MenuItem.Template>
                        <ControlTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition
                                        Width="*" />
                                    <ColumnDefinition
                                        Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock
                                    Text="Run"
                                    Grid.Column="0"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Stretch"
                                    Margin="32,0,16,0"
                                    IsHitTestVisible="False"
                                    MinWidth="30" />
                                <ToolBarTray
                                    IsLocked="True"
                                    Grid.Column="1"
                                    Background="Transparent"
                                    Focusable="False">
                                    <ToolBar
                                        Loaded="ToolBar_Loaded">
                                        <Button
                                            Command="automator:AutomatorCommands.RunTask"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/runtask.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                        <Button
                                            Command="automator:AutomatorCommands.RunTaskWithDependencies"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/rundependent.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                    </ToolBar>
                                </ToolBarTray>
                            </Grid>
                        </ControlTemplate>
                    </MenuItem.Template>
                </MenuItem>
                <Separator />
                <MenuItem
                    Header="Order"
                    Margin="1">
                    <MenuItem.Template>
                        <ControlTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition
                                        Width="*" />
                                    <ColumnDefinition
                                        Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock
                                    Text="Order"
                                    Grid.Column="0"
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Stretch"
                                    Margin="32,0,16,0"
                                    IsHitTestVisible="False"
                                    MinWidth="30" />
                                <ToolBarTray
                                    IsLocked="True"
                                    Grid.Column="1"
                                    Background="Transparent"
                                    Focusable="False">
                                    <ToolBar
                                        Loaded="ToolBar_Loaded">
                                        <Button
                                            Command="automator:AutomatorCommands.MoveTaskUp"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/back.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                        <Button
                                            Command="automator:AutomatorCommands.MoveTaskDown"
                                            ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                            <Image
                                                Source="resources/forward.png"
                                                Width="16"
                                                Height="16"
                                                Margin="2"
                                                Style="{StaticResource ToolbarImageStyle}" />
                                        </Button>
                                    </ToolBar>
                                </ToolBarTray>
                            </Grid>
                        </ControlTemplate>
                    </MenuItem.Template>
                </MenuItem>
            </ContextMenu>
            
            <HierarchicalDataTemplate
                x:Key="workflowTreeTemplate"
                DataType="{x:Type core:Task}"
                ItemsSource="{Binding Path=DependentTasks}">
                <Border
                    BorderBrush="{x:Static SystemColors.ControlDarkBrush}"
                    BorderThickness="0"
                    x:Name="itemBorder"
                    ContextMenu="{StaticResource mnuBorder}">
                    <StackPanel
                        Orientation="Horizontal"
                        Margin="6,0,4,0"
                        MinWidth="200">
                        <CheckBox
                            IsChecked="{Binding Path=IsActive}"
                            IsEnabled="{Binding Path=IsEnabled}"
                            VerticalAlignment="Center"
                            Focusable="False"
                            x:Name="chkActive"
                            Click="ChkActive_Click" />
                        <Image
                            Width="16"
                            Height="16"
                            Source="{Binding Path=State, Converter={StaticResource TaskStateImageConverter}}"
                            Margin="8,4,0,4"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"
                            x:Name="imgState" />
                        <Image
                            Width="32"
                            Height="32"
                            Source="{Binding TaskImage}"
                            Margin="4" />
                        <StackPanel
                            Orientation="Vertical">
                            <TextBlock
                                FontWeight="Bold"
                                Text="{Binding Path=Title}"
                                Margin="0,4,0,0"
                                FontSize="12"
                                x:Name="lblTitle" />
                            <TextBlock
                                FontWeight="Light"
                                Text="{Binding Path=CommandText, Converter={StaticResource CommandLineConverter}}"
                                Foreground="{x:Static SystemColors.GrayTextBrush}"
                                FontSize="12"
                                x:Name="lblCommand" />
                        </StackPanel>
                    </StackPanel>
                </Border>
                <HierarchicalDataTemplate.Triggers>
                    <DataTrigger
                        Binding="{Binding Path=State}"
                        Value="Executing">
                        <Setter
                            TargetName="itemBorder"
                            Property="BorderThickness"
                            Value="1" />
                        <Setter
                            TargetName="itemBorder"
                            Property="Background"
                            Value="{x:Static SystemColors.ControlLightBrush}" />
                    </DataTrigger>
                    <DataTrigger
                        Binding="{Binding Path=State}"
                        Value="Ready">
                        <Setter
                            TargetName="imgState"
                            Property="Visibility"
                            Value="Collapsed" />
                    </DataTrigger>
                    <DataTrigger
                        Binding="{Binding Path=State}"
                        Value="NotExecuted">
                        <Setter
                            TargetName="imgState"
                            Property="Visibility"
                            Value="Collapsed" />
                    </DataTrigger>
                    <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
                            <Condition
                                Binding="{Binding Path=IsActive}"
                                Value="False" />
                            <Condition
                                Binding="{Binding Path=IsEnabled}"
                                Value="True" />
                        </MultiDataTrigger.Conditions>
                        <Setter
                            TargetName="lblTitle"
                            Property="Foreground"
                            Value="{x:Static SystemColors.GrayTextBrush}" />
                        <Setter
                            TargetName="lblCommand"
                            Property="Foreground"
                            Value="{x:Static SystemColors.GrayTextBrush}" />
                    </MultiDataTrigger>
                </HierarchicalDataTemplate.Triggers>
            </HierarchicalDataTemplate>
        
            <HierarchicalDataTemplate
                x:Key="solutionTreeTemplate"
                DataType="{x:Type runtime:RuntimeEntity}"
                ItemsSource="{Binding Path=Workflows}">
                <StackPanel Orientation="Horizontal" Margin="2">
                    <StackPanel.ContextMenu>
                        <ContextMenu>
                            <MenuItem
                                Command="automator:AutomatorCommands.EditWorkflow"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                            <MenuItem
                                Command="automator:AutomatorCommands.RemoveWorkflow"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                            <MenuItem
                                Command="automator:AutomatorCommands.DeleteWorkflow"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        </ContextMenu>
                    </StackPanel.ContextMenu>
                    <Image Source="{Binding Converter={StaticResource WorkflowImageConverter}}"
                           Width="16" Height="16" VerticalAlignment="Center" Margin="2" />
                    <TextBlock VerticalAlignment="Center" Text="{Binding Path=Name}" Margin="2" />
                </StackPanel>
            </HierarchicalDataTemplate>
        
        </ResourceDictionary>
    </Window.Resources>
    <Window.TaskbarItemInfo>
        <TaskbarItemInfo
            x:Name="taskbarInfo"
            Description="Automator" />
    </Window.TaskbarItemInfo>
    <extToolkit:BusyIndicator
        IsBusy="False"
        x:Name="WaitForm">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition
                    Height="Auto" />
                <RowDefinition
                    Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <ToolBarTray
                Grid.Row="0">
                <ToolBar>
                    <ToolBar.Template>
                        <ControlTemplate>
                            <ItemsPresenter />
                        </ControlTemplate>
                    </ToolBar.Template>
                    <Menu
                        Grid.Row="0"
                        Background="Transparent"
                        Margin="4,0,0,2">
                        <MenuItem
                            Header="File">
                            <MenuItem
                                Header="New"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="New"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.NewWorkflow"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/workflow.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.NewSolution"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/application.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <MenuItem
                                Header="Open"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Open"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.OpenWorkflow"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/open.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.OpenSolution"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/opensolution.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Header="Save"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Save"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="ApplicationCommands.Save"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/save.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="ApplicationCommands.SaveAs"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <StackPanel
                                                            Orientation="Horizontal">
                                                            <Image
                                                                Width="16"
                                                                Height="16"
                                                                Margin="2"
                                                                Visibility="Collapsed" />
                                                            <TextBlock
                                                                VerticalAlignment="Center"
                                                                Margin="2"
                                                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Command.Text}" />
                                                        </StackPanel>
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.SaveAll"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/saveall.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Header="Exit"
                                Click="MnuExit_Click" />
                        </MenuItem>
                        <MenuItem
                            Header="Edit">
                            <MenuItem
                                Header="Add"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Add"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.AddTask"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/addtask.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.AddDependency"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/adddependent.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <MenuItem
                                Header="Edit"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Edit"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.EditTask"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/edit.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.DeleteTask"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/delete.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Header="Clipboard"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Clipboard"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.Cut"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/cut.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.Copy"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/copy.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.Paste"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/paste.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Header="Order"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Order Task"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.MoveTaskUp"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/back.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.MoveTaskDown"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/forward.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                        </MenuItem>
                        <MenuItem
                            Header="View">
                            <MenuItem
                                Command="automator:AutomatorCommands.ViewSolution"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}"
                                InputGestureText="F7">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/application.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem
                                Command="automator:AutomatorCommands.ViewOutput"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/output.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem
                                Command="automator:AutomatorCommands.ViewClipboard"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/clipboard.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Command="automator:AutomatorCommands.ViewStartPage"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/startpage.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                        </MenuItem>
                        <MenuItem
                            Header="Run">
                            <MenuItem
                                Header="Run Workflow"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Workflow"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.RunWorkflow"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/run.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.ResetWorkflow"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/runreset.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Header="Run Task"
                                Margin="1">
                                <MenuItem.Template>
                                    <ControlTemplate>
                                        <Grid>
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition
                                                    Width="*" />
                                                <ColumnDefinition
                                                    Width="Auto" />
                                            </Grid.ColumnDefinitions>
                                            <TextBlock
                                                Text="Task"
                                                Grid.Column="0"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Stretch"
                                                Margin="32,0,16,0"                                                
                                                IsHitTestVisible="False"
                                                MinWidth="30" />
                                            <ToolBarTray
                                                IsLocked="True"
                                                Grid.Column="1"
                                                Background="Transparent"
                                                Focusable="False">
                                                <ToolBar
                                                    Loaded="ToolBar_Loaded">
                                                    <Button
                                                        Command="automator:AutomatorCommands.RunTask"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/runtask.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                    <Button
                                                        Command="automator:AutomatorCommands.RunTaskWithDependencies"
                                                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource TooltipConverter}}">
                                                        <Image
                                                            Source="resources/rundependent.png"
                                                            Width="16"
                                                            Height="16"
                                                            Margin="2"
                                                            Style="{StaticResource ToolbarImageStyle}" />
                                                    </Button>
                                                </ToolBar>
                                            </ToolBarTray>
                                        </Grid>
                                    </ControlTemplate>
                                </MenuItem.Template>
                            </MenuItem>
                        </MenuItem>
                        <MenuItem
                            Header="Tools">
                            <MenuItem
                                Command="automator:AutomatorCommands.SqlSettings"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                            <MenuItem
                                Command="automator:AutomatorCommands.ProxySettings"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        </MenuItem>
                        <MenuItem
                            Header="Help">
                            <MenuItem
                                Command="automator:AutomatorCommands.ProjectPage"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/web.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem
                                Command="automator:AutomatorCommands.OnlineDocumentation"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                                <MenuItem.Icon>
                                    <Image
                                        Source="resources/help.png"
                                        Width="16"
                                        Height="16"
                                        Margin="2" />
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem
                                Header="Integrated Projects">
                                <MenuItem
                                    Header="AvalonDock"
                                    Click="WebAvalonDock_Click">
                                    <MenuItem.Icon>
                                        <Image
                                            Source="resources/web.png"
                                            Width="16"
                                            Height="16"
                                            Margin="2" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem
                                    Header="WPFToolkit Extended"
                                    Click="WebWPFToolkit_Click">
                                    <MenuItem.Icon>
                                        <Image
                                            Source="resources/web.png"
                                            Width="16"
                                            Height="16"
                                            Margin="2" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem
                                    Header="AvalonEdit"
                                    Click="WebAvalonEdit_Click">
                                    <MenuItem.Icon>
                                        <Image
                                            Source="resources/web.png"
                                            Width="16"
                                            Height="16"
                                            Margin="2" />
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem
                                    Header="AvalonWizard"
                                    Click="WebAvalonWizard_Click">
                                    <MenuItem.Icon>
                                        <Image
                                            Source="resources/web.png"
                                            Width="16"
                                            Height="16"
                                            Margin="2" />
                                    </MenuItem.Icon>
                                </MenuItem>                            
                            </MenuItem>
                            <Separator />
                            <MenuItem
                                Command="automator:AutomatorCommands.About"
                                Header="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}" />
                        </MenuItem>
                    </Menu>
                </ToolBar>
            </ToolBarTray>
            <ToolBarTray
                Grid.Row="1">
                <ToolBar
                    Band="1"
                    BandIndex="1">
                    <Button
                        Command="automator:AutomatorCommands.NewWorkflow"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <StackPanel
                            Orientation="Horizontal">
                            <Image
                                Source="resources/workflow.png"
                                Width="16"
                                Height="16"
                                Margin="2"
                                Style="{StaticResource ToolbarImageStyle}" />
                            <TextBlock
                                VerticalAlignment="Center"
                                Margin="2"
                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Command.Text}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.NewSolution"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/application.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.OpenWorkflow"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/open.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.OpenSolution"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/opensolution.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="ApplicationCommands.Save"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/save.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.SaveAll"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/saveall.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Separator />
                    <Button
                        Command="automator:AutomatorCommands.AddTask"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <StackPanel
                            Orientation="Horizontal">
                            <Image
                                Source="resources/addtask.png"
                                Width="16"
                                Height="16"
                                Margin="2"
                                Style="{StaticResource ToolbarImageStyle}" />
                            <TextBlock
                                VerticalAlignment="Center"
                                Margin="2"
                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Command.Text}" />
                        </StackPanel>
                    </Button>
                    <Separator />
                    <Button
                        Command="automator:AutomatorCommands.Cut"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/cut.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.Copy"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/copy.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.Paste"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/paste.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                    <Separator />
                    <Button
                        Command="automator:AutomatorCommands.RunWorkflow"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <StackPanel
                            Orientation="Horizontal">
                            <Image
                                Source="resources/run.png"
                                Width="16"
                                Height="16"
                                Margin="2"
                                Style="{StaticResource ToolbarImageStyle}" />
                            <TextBlock
                                VerticalAlignment="Center"
                                Margin="2"
                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=Command.Text}" />
                        </StackPanel>
                    </Button>
                    <Button
                        Command="automator:AutomatorCommands.ResetWorkflow"
                        ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Command.Text}">
                        <Image
                            Source="resources/runreset.png"
                            Width="16"
                            Height="16"
                            Margin="2"
                            Style="{StaticResource ToolbarImageStyle}" />
                    </Button>
                </ToolBar>
            </ToolBarTray>
            <ad:DockingManager
                Grid.Row="2"
                HorizontalAlignment="Stretch"
                Name="dockingManager"
                VerticalAlignment="Stretch"
                ActiveDocumentChanged="DockingManager_ActiveDocumentChanged"
                Loaded="DockingManager_Loaded">
                <ad:ResizingPanel
                    Orientation="Vertical">
                    <ad:ResizingPanel Orientation="Horizontal">
                        <ad:DocumentPane />
                        <ad:DockablePane ad:ResizingPanel.ResizeWidth="220" SelectedIndex="0">
                            <classes:SolutionDocument 
                                Title="Solution Explorer"
                                HideOnClose="True"
                                x:Name="solutionContent"
                                Icon="resources/application.png">
                                <TreeView 
                                    Focusable="True" 
                                    AllowDrop="False" 
                                    ItemTemplate="{StaticResource solutionTreeTemplate}" 
                                    x:Name="solutionTree"
                                    MouseDoubleClick="LstWorkflows_MouseDoubleClick"
                                    ItemContainerStyle="{StaticResource solutionTreeItemStyle}" />
                            </classes:SolutionDocument>
                            <ad:DockableContent
                                Title="Task Clipboard"
                                HideOnClose="True"
                                x:Name="clipboardContent"
                                Icon="resources/clipboard.png">
                                <ListView x:Name="lstClipboard" SelectionMode="Single" MouseDoubleClick="LstClipboard_MouseDoubleClick">
                                    <ListView.View>
                                        <GridView>
                                            <GridView.ColumnHeaderContainerStyle>
                                                <Style>
                                                    <Setter
                                                        Property="FrameworkElement.Visibility"
                                                        Value="Collapsed" />
                                                </Style>
                                            </GridView.ColumnHeaderContainerStyle>
                                            <GridViewColumn CellTemplate="{StaticResource clipboardTaskTemplate}" />
                                        </GridView>
                                    </ListView.View>
                                </ListView>
                            </ad:DockableContent>
                        </ad:DockablePane>
                    </ad:ResizingPanel>
                    <ad:DockablePane
                        ad:ResizingPanel.ResizeHeight="220" SelectedIndex="0">
                        <ad:DockableContent
                            Title="Output"
                            x:Name="outputContent"
                            HideOnClose="True"
                            Icon="resources/output.png">
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <StackPanel Orientation="Horizontal" Grid.Row="0">
                                    <TextBlock VerticalAlignment="Center" Margin="4" Text="Show output from:" />
                                    <ComboBox
                                        Focusable="False"
                                        IsReadOnly="True" 
                                        VerticalAlignment="Center" 
                                        VerticalContentAlignment="Center" 
                                        Margin="4"
                                        Padding="4"
                                        MinWidth="200" 
                                        x:Name="cmbOutputTargets" 
                                        SelectionChanged="cmbOutputTargets_SelectionChanged" />
                                </StackPanel>
                                <ListView
                                    Grid.Row="1"
                                SelectionMode="Single"
                                x:Name="lstOutput"
                                MouseDoubleClick="LstOutput_MouseDoubleClick">
                                    <ListView.Resources>
                                        <Style
                                        TargetType="ListViewItem">
                                            <Style.Triggers>
                                                <DataTrigger
                                                Binding="{Binding Path=MessageType}"
                                                Value="Error">
                                                    <Setter
                                                    Property="Foreground"
                                                    Value="Red" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </ListView.Resources>
                                    <ListView.View>
                                        <GridView>
                                            <GridView.ColumnHeaderContainerStyle>
                                                <Style>
                                                    <Setter
                                                    Property="FrameworkElement.Visibility"
                                                    Value="Visible" />
                                                </Style>
                                            </GridView.ColumnHeaderContainerStyle>
                                            <GridViewColumn
                                            Width="48">
                                                <GridViewColumn.CellTemplate>
                                                    <DataTemplate>
                                                        <Image
                                                        Width="16"
                                                        Height="16"
                                                        Source="{Binding Path=MessageType, Converter={StaticResource LogImageConverter}}"
                                                        Margin="4,4,8,4"
                                                        VerticalAlignment="Center"
                                                        HorizontalAlignment="Center" />
                                                    </DataTemplate>
                                                </GridViewColumn.CellTemplate>
                                            </GridViewColumn>
                                            <GridViewColumn
                                            DisplayMemberBinding="{Binding Path=MessageTime, Converter={StaticResource LogDateTimeConverter}}"
                                            Header="Date"
                                            Width="150" />
                                            <GridViewColumn
                                            DisplayMemberBinding="{Binding Path=Message}"
                                            Header="Message"
                                            Width="600" />
                                        </GridView>
                                    </ListView.View>
                                </ListView>
                            </Grid>
                        </ad:DockableContent>
                    </ad:DockablePane>
                </ad:ResizingPanel>
            </ad:DockingManager>
        </Grid>
    </extToolkit:BusyIndicator>
</Window>